jQuery(function() {
    var tabPanel = new SqlPlusPanel({"container": "db-list-panel"});

    jQuery("#db-list tr td a.rename").click(function() {
        var params = [];
        var name = PageContext.getAttribute("connectionName");
        var oldDatabase = PageContext.getAttribute("database");
        var newDatabase = PageContext.getAttribute("newDatabase");
        params[params.length] = "name=" + encodeURIComponent(name);
        params[params.length] = "oldDatabase=" + encodeURIComponent(oldDatabase);
        params[params.length] = "newDatabase=" + encodeURIComponent(newDatabase);
        alert("rename: " + params.join("&"));
    });

    jQuery("#alter-panel .panel-title span.close").click(function() {
        jQuery("#alter-panel").hide();
    });

    jQuery("#alter-panel input.cancel").click(function() {
        jQuery("#alter-panel").hide();
    });

    jQuery("#alter-panel input.ensure").click(function() {
        var params = [];
        var name = PageContext.getAttribute("connectionName");
        var database = jQuery(this).attr("database");

        params[params.length] = "name=" + encodeURIComponent(name);
        params[params.length] = "database=" + encodeURIComponent(database);
        AlterPanel.running();

        jQuery.ajax({
            "type": "post",
            "url": PageContext.getContextPath() + "/webcat/database/drop.html",
            "dataType": "json",
            "data": params.join("&"),
            "error": function() {
                AlterPanel.error("系统错误，请稍后再试！");
                AlterPanel.setEnabled(true);
            },
            "success": function(result) {
                if(result != null) {
                    jQuery("#alter-panel input.cancel").unbind();
                    jQuery("#alter-panel input.cancel").click(function() {
                        window.location.reload();
                    });
                    AlterPanel.show(result.message);
                }
                else {
                    AlterPanel.error("系统错误，请稍后再试！");
                    AlterPanel.setEnabled(true);
                }
            }
        });
    });

    jQuery("#db-list tr td a.remove").click(function() {
        var database = jQuery(this).attr("database");
        jQuery("#alter-panel input.ensure").attr("database", database);
        AlterPanel.submit(Sql.highlight("-- drop database\r\ndrop database " + database + ";"));
    });
});

jQuery(function() {
    Dragable.registe("alter-panel");

    jQuery("#create-tablespace-btn").click(function() {
        var name = PageContext.getAttribute("connectionName");
        window.location.href = PageContext.getContextPath() + "/webcat/oracle/tablespace.html?name=" + encodeURIComponent(name);
    });

    jQuery("#create-user-btn").click(function() {
        var name = PageContext.getAttribute("connectionName");
        window.location.href = PageContext.getContextPath() + "/webcat/oracle/tablespace.html?name=" + encodeURIComponent(name);
    });
});

jQuery(function() {
    jQuery("#db-list tr").mouseover(function() {
        this.style.backgroundColor = "#ffda5a";
    });

    jQuery("#db-list tr").mouseout(function() {
        this.style.backgroundColor = "#ffffff";
    });
});

jQuery(function() {
    jQuery(window).trigger("resize");
});

jQuery(function() {
    setTimeout(function() {
        alert("Oracle数据库支持还在开发中,功能暂不可用!");
    }, 100);
});
